<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use EasyWeChat\Foundation\Application;

class Wechat extends Model
{
    //
    private static $_instance = null;

    protected $app;

    public function __construct() {
        parent::__construct();
        $this->app = new Application($this->config());
        //$this->setMenus();
    }

    //私有克隆函数，防止外办克隆对象
    private function __clone() {}

    //静态方法，单例统一访问入口
    static public function getInstance() {
        if (is_null ( self::$_instance ) || isset ( self::$_instance )) {
            self::$_instance = new self ();
        }
        return self::$_instance;
    }

    public function app() {
        return $this->app;
    }


    private function config(){
        return [

            'debug'  => env("WECHAT_DEBUG"),
            'app_id' => env("WECHAT_APP_ID"),
            'secret' => env("WECHAT_SECRET"),
            'token'  => env("WECHAT_TOKEN"),
            'aes_key' => env("WECHAT_AES_KEY"), // 可选
            'log' => [
                'level' => env("WECHAT_LOG_LEVEL"),
                'file'  => env("WECHAT_LOG_FILE"), // XXX: 绝对路径！！！！
            ],
            'oauth' => [
                'scopes'   => [env("WECHAT_OAUTH_SCOPES")],
                'callback' => env("WECHAT_OAUTH_CALLBACK"),
            ],

            'payment' => [
                'merchant_id'        => env("WECHAT_PAYMENT_MERCHANT_ID"),
                'key'                => env("WECHAT_PAYMENT_KEY"),
                'cert_path'          => env("WECHAT_PAYMENT_CERT_PATH"), // XXX: 绝对路径！！！！
                'key_path'           => env("WECHAT_PAYMENT_KEY_PATH"),      // XXX: 绝对路径！！！！
                'notify_url'         => env("WECHAT_NOTIFY_URL"),       // 你也可以在下单时单独设置来想覆盖它

                // 'device_info'     => '013467007045764',
                // 'sub_app_id'      => '',
                // 'sub_merchant_id' => '',
                // ...
            ],


        ];
    }

    private function setMenus(){
        $this->app->menu->add($this->menuButtons());
    }


    private  function  menuButtons(){

        return [
            [
                "name" => "e美商城",
                "sub_button"  => [
                    [
                        "type" => "view",
                        "name" => "商城首页",
                        "url"  => "http://www.520mrw.com/Shop/index/"
                    ],
                    [
                        "type" => "view",
                        "name" => "在线预约",
                        "url"  => "http://www.520mrw.com/Sellers/index"
                    ],
                    [
                        "type" => "view",
                        "name" => "用户中心",
                        "url"  => "http://www.520mrw.com/Member/index"
                    ],
                    [
                        "type" => "view",
                        "name" => "体验反馈表",
                        "url"  => "https://sojump.com/jq/15276636.aspx"
                    ],
                    [
                        "type" => "view",
                        "name" => "免费体验预约",
                        "url"  => "https://www.sojump.hk/jq/15273575.aspx"
                    ]
                ]
            ],
            [
                "name"       => "分销推广",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "分销中心",
                        "url" =>"http://www.520mrw.com/Distribution/index"
                    ],
                    [
                        "type" => "click",
                        "name" => "我的二维码",
                        "key" =>"V1001_my_qrcode"
                    ],
                    [
                        "type" => "view",
                        "name" => "APP下载",
                        "url"  => "http://www.520mrw.com/appDownload"
                    ]

                ],
            ],
            [
                "name"       => "联系我们",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "关于我们",
                        "url"  => "https://mp.weixin.qq.com/mp/getmasssendmsg?__biz=MzI4ODQ4NTE5OQ%3D%3D#wechat_webview_type=1&wechat_redirect"
                    ],
                    [
                        "type" => "view",
                        "name" => "我要购物",
                        "url"  => "http://mp.weixin.qq.com/s/IaDtdRXsSxuXaTsA9n4v2A"
                    ],
                    [
                        "type" => "view",
                        "name" => "售后服务",
                        "url"  => "http://mp.weixin.qq.com/s/S_dk4p-T5UwFv7jNRhLAcw"
                    ],
                    [
                        "type" => "view",
                        "name" => "商务合作",
                        "url"  => "http://mp.weixin.qq.com/s/nvm-BPTyoNTj5QW6T5P0GA"
                    ],
                    [
                        "type" => "view",
                        "name" => "购物保障",
                        "url"  => "http://mp.weixin.qq.com/s/5Qw3mW31y5SWduiX3Dg9pA"
                    ]
                ],
            ],
        ];
    }


}
